#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1005;
const int MOD = 998244353;

int n;
LL ans = 0;
LL arr[N];
// dp[i][d]表示的意思: 以arr[i]结尾,公差为d的等差数列 的个数
unordered_map<int,unordered_map<int,int>> dp;

int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>arr[i];
    for(int i=2;i<=n;i++){
        for(int j=1;j<i;j++){
            LL d = arr[j]-arr[i];
            ans = (ans + dp[j][d] + 1)%MOD;
            dp[i][d] = (dp[i][d]+dp[j][d]+1)%MOD;
        }
    }
    cout<<(ans+n)%MOD<<endl;
    return 0;
}